package com.sino.androiddesign.database.nativeDataBase

import android.content.Context
import android.database.sqlite.SQLiteDatabase
import android.database.sqlite.SQLiteOpenHelper
import android.util.Log
import com.sino.androiddesign.main.DesignApp

class SQLiteDbHelper(context: Context) : SQLiteOpenHelper(context, SQLiteDbHelper.db_name, null, db_version) {


    private val create_table_students_sql = "create table $table_student (id integer primary key autoincrement," +
            "name varchar(20) not null,cls varchar(20) not null);"

       //    原生数据库 1: 创建表
     override fun onCreate(db: SQLiteDatabase?) {
         //创建表格
         db!!.execSQL(create_table_students_sql)
     }


     override fun onUpgrade(db: SQLiteDatabase?, oldVersion: Int, newVersion: Int) {
         Log.e("SQLiteDbHelper","表格更新")
         when(oldVersion){
             1->{

             }
             2->{

             }
         }
     }

    override fun onOpen(db: SQLiteDatabase?) {
        super.onOpen(db)
        Log.e("SQLiteDbHelper","onOpen")
    }

     companion object {
         val db_name:String = "database.db"
         val db_version:Int = 1

         val table_student ="students"

         val instance:SQLiteDbHelper by lazy { SQLiteDbHelper(DesignApp.appContext) }

     }



}